<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.Building"%>
<%@ page import="com.model.Admin"%>
<%@ page import="com.control.BuildingControl"%>
<%@ page import="com.control.AdminControl"%>
<%@ page import="com.util.PageResultSet"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>查询管理员</title>
	</head>
	<body>
		<%
	    request.setCharacterEncoding("UTF-8");
	    int admin_building = 0;
	    String ToolBar = "";
	    int curPage = 1;
	   	if(request.getParameter("admin_building") != null) {
	    	admin_building = Integer.parseInt(request.getParameter("admin_building"));
	    	session.setAttribute("admin_building",admin_building);	
	    }
	%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							管理员信息列表
						</legend>
						<form action="adminInfo_show.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
										请选择寝室楼:
										<select name="admin_building" size="1">
										<%
											if(session.getAttribute("admin_building") != null) {
	    										admin_building = (Integer)session.getAttribute("admin_building");
	    									}
										 %>
											<option value="0" <%if(admin_building == 0) {%>selected="selected"<%}%>>全部</option>
											<%
											BuildingControl control = new BuildingControl();
											ArrayList<Building> blist = new ArrayList<Building>();
											blist = control.getBuildingList(); 
											for(int i=0; i<blist.size(); i++) {
												Building building = blist.get(i);
										%>
											<option value="<%= building.getBuilding_id()%>" <%if(admin_building == building.getBuilding_id()%><%){%>selected="selected"<%}%>><%=building.getBuilding_name() %></option>
											<%}%>
											
										</select>
										<input type="submit" value="查询" />
										<input name="insert" type="button" value="添加管理员"
											onclick="window.location.href='admin_insert.jsp'" />
									</td>
								</tr>
							</table>
							<table width="60%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													账号
												</td>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													姓名
												</td>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF">
													性别
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													电话号码
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													所属寝室楼
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													操作
												</td>
								</tr>
								<%
									AdminControl acontrol = new AdminControl();
									ArrayList<Admin> list = new ArrayList<Admin>();
									list = acontrol.getAdminInformation(admin_building);
									if(request.getParameter("cur_page")!= null) {
										curPage = Integer.parseInt(request.getParameter("cur_page")); 
									}
									PageResultSet p = new PageResultSet(list,curPage);
									ArrayList<Admin> nowlist = new ArrayList<Admin>();
									nowlist = (ArrayList<Admin>)p.getData();
									for(int i=0; i<nowlist.size(); i++) {
										Admin admin = nowlist.get(i);
							 	%>
								 	<tr>
        								<td height="25" align="center"><%=admin.getAdmin_num()%></td>
 										<td height="25" align="center"><%=admin.getAdmin_name()%></td>
 										<td height="25" align="center"><%=admin.getAdmin_sex()%></td>
 										<td height="25" align="center"><%=admin.getAdmin_tel()%></td>
 										<td height="25" align="center"><%=admin.getAdmin_building_name()%></td>	
 		 								<td height="25" align="center"><a href="adminInfo_change.jsp?id=<%=admin.getAdmin_id()%>">修改</a> | <a href="javascript:if(confirm('确认删除吗?'))window.location='admin_delete.jsp?id=<%=admin.getAdmin_id()%>'">删除</a></td>
   									</tr>
   									<%}
   										
										String fileName = "adminInfo_show.jsp";
										ToolBar = p.getToolBar(fileName);
									%>
							</table>
							<%=ToolBar %>
							
							</td>
							</tr>
							</table>
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
